import { createRouter, createWebHashHistory } from 'vue-router'
import { Toast } from 'vant'
const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            component: () => import('../views/home/Home_1.vue')
        },
        {
            path: '/home',
            component: () => import('../views/home/Home_1.vue')
        },
        {
            path: '/cart',
            component: () => import('../views/cart/Cart_1.vue'),
            meta:{
                isAuth:true
            }
        },
        {
            path: '/mine',
            component: () => import('../views/mine/Mine_1.vue'),
            meta:{
                isAuth:true
            }
        },
        {
            path: '/order',
            component: () => import('../views/order/Order_1.vue'),
            meta:{
                isAuth:true
            }
        },
        {
            path: '/store',
            component: () => import('../views/store/store.vue')
        },
        {
            path: '/createorder',
            component: () => import('../views/createOrder/createOrder.vue'),
            meta:{
                isAuth:true
            }
        },
        {
            path: '/address',
            component: () => import('../views/address/address.vue'),
            meta:{
                isAuth:true
            }
        },
        {
            path: '/addressedit',
            component: () => import('../views/addressEdit/addressEdit.vue'),
            meta:{
                isAuth:true
            }
        },
        {
            path: '/login',
            component: () => import('../views/login/login.vue')
        },
        {
            path: '/register',
            component: () => import('../views/register/register.vue')
        },
        {
            path: '/userinfo',
            component: () => import('../views/userinfoedit/userInfo.vue'),
            meta:{
                isAuth:true
            }
        },
    ]
})
router.beforeEach((to,from,next)=>{
    if(to.meta.isAuth){
        if(localStorage.isLogin === 'login'){
            next()
        }else{
            next('/login')
            Toast('请先登录')
        }
    }else{
        next()
    }
})
export default router